<?php
namespace App\Api\Fcjd;

use PhalApi\Api;


/**
 * 获取下级代理总数接口
 * @desc 读取phone_kami表数据
 */
class UserTj extends Api {
    public function getRules() {
        return array(
            'getAgent' => array(
                'username' => array('name' => 'username', 'type' => 'string', 'require' => true, 'desc' => '用户名'),
            ),
        );
    }

    /**
     * 全部数据
     * @desc 获取phone_kami表数据
     * @return array items 数据列表
     * @return int total 总记录数
     */
    public function getAgent() {

        $where = array(
            'Invitations LIKE ?' => '%'.$this->username."%",
        );
        $agent = \PhalApi\DI()->notorm->phalapi_user->where('Invitation', $this->username)->count();
        $AllAgent = \PhalApi\DI()->notorm->phalapi_user->where($where)->select('username')->fetchAll();
        if($AllAgent){
            $Allusername = array_column($AllAgent, 'username');
        }
        $phone_count = \PhalApi\DI()->notorm->phone_list->where(array('username' => $Allusername))->count(); // 查询username在$Allusername数组中的记录数
        \PhalApi\DI()->response->addResult('success', true);
        return array( 'agent' => $agent, 'AllAgent' => count($AllAgent), 'phone_count' => $phone_count, );
    }
    
    
}